import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;

public class SocketService {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(4444);
            serverSocket.setReceiveBufferSize(101);
            while (true) {
                final java.net.Socket accept = serverSocket.accept();
                System.out.println('1');

                Runnable runnable = new Runnable() {
                    public void run() {
                        try {
                            InputStream inputStream = accept.getInputStream();
                             Integer i = 0;
                            while (true) {
                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                i++;
                                byte [] b=new byte[30];
                                int available = inputStream.available();
                                System.out.println("可利用:"+available);
//                                if (available>30) {
//                                    inputStream.read(b);
//                                    String s = new String(b,"utf-8");
//                                    System.out.println(s);
//                                    System.out.println("count:"+i);
//                                }

                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                };
                new Thread(runnable).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
